<?php

class Ddup_Featured_Model_Products extends Mage_Core_Model_Abstract
{
	/**
     * Init resource model
     */
    protected function _construct()
    {
        parent::_construct();
        $this->_init('featured/products');
    }
    
    public function loadPost($data)
    {
    	if (isset($data['id'])) {
    		$this->setData('featured_products_id',$data['id']);
    	} else {    		
   			$this->setData('created',date('Y-m-d H:i:s'));
    	}
    	if (isset($data['title'])) {
    		$this->setData('title',$data['title']);
    	}
    	if (isset($data['is_random'])) {
    		$this->setData('is_random',$data['is_random']);
    	}
    	if (isset($data['show_qty'])) {
    		$this->setData('show_qty',$data['show_qty']);
    	}    	
   		$this->setData('updated',date('Y-m-d H:i:s'));
   		
    	if (isset($data['products']) && !empty($data['products'])){
    		parse_str($data['products'], $products);
    		if ($products){
    			foreach($products as $key=>$value){
    				if (!is_numeric($key)){
    					unset($products[$key]);
    				}
    			}
    			$this->setData('products', join(',', array_keys($products)));
    		}
    	}
    	 
    	return $this;
    }
}